﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MsForgeReboot.Framework.Entities;
using System.Configuration;
using System.Data.SqlClient;
using System.Net.Mail;
using System.Net;
using MsForgeReboot.Framework.Interfaces;
using MsForgeReboot.Framework.TownCrierChannelTools;
//using TownSuite.TownPostman;

namespace MsForgeReboot.Framework.TownCrierChannels {
    public class MassMailChannel : IChannel {

        #region IChannel Members

        public Event Source { get; set; }
        public string MailAddress { get; set; }

        public DeliveryResult DeliverEvent(Event source) {
            DeliveryResult result = new DeliveryResult();
            result.DeliveryChannel = "MassMailer";

            MailMessage msg = new MailMessage("no-reply@msforge.net", this.MailAddress);
            msg.Subject = String.Format("Poziv na {0} skupljanje, tema {1}", this.Source.OrganizedBy.Title, this.Source.Topic);
            msg.Body = this.Source.Body;
            msg.IsBodyHtml = true;

            try {
                // TODO add the needed data here for the server...
                SmtpClient client = new SmtpClient();
                client.Send(msg);
                result.DeliveredOn = DateTime.UtcNow;
                result.Success = true;
            } catch (Exception e) {
                result.Success = false;
                result.Message = e.Message;
            } 

            return result;
        }

        public DeliveryResult DeliverEvent() {
            return this.DeliverEvent(this.Source);
        }

        #endregion
    }
}
